/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Matrimonial;

import Admin.*;
import Login.MySqlConnector;
import java.io.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Bharath
 */
public class ViewMatMember extends HttpServlet {

    MySqlConnector ms;
    ViewMatMemberDao vmd;
    ManageMembersDao mmd;
    private String rcheck;
    private String gender;
    private String age;
    private String qual;

    public ViewMatMember() {
        ms = new MySqlConnector();
        vmd = new ViewMatMemberDao();
        mmd = new ManageMembersDao();
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException, Exception {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            rcheck = request.getParameter("rcheck");
            System.out.println("rcheck is ---------->" + rcheck);
            //rcheck in session\\
            HttpSession hs = request.getSession(true);
            hs.setAttribute("view_rcheck", rcheck);
            System.out.println("rcheck after set session is ---------- > " + rcheck);

            /********************************  View Members ************************************/
            if (request.getParameter("ViewMem") != null) {
                try {
                    System.out.println(" View Member button clicked ");
                    MarRegisterBean status = vmd.view_member(rcheck);
                    System.out.println("******" + status);
                    if (status != null) {
                        System.out.println("in status true");
                        request.setAttribute("rbeanmatview", status);
                        request.getRequestDispatcher("Matrimonial/FullMatView.jsp").forward(request, response);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }//End ViewMatMember

            /*******************  Delete Members ***********************************************/
            if (request.getParameter("DeleteMem") != null) {
                System.out.println(" Delete Member button clicked ");
                boolean b = mmd.Delete_Member(rcheck);
                if (b == true) {

                    System.out.println("in b==true condition " + b);
                    out.print("<script language = 'javascript'>alert('Member deleted succesfull'); location='Matrimonial/MatrAdminHome.jsp'</script>");
                    //request.getRequestDispatcher("/AllMembers.jsp").forward(request, response);
                }
            }//End DeleteMember

            /***************************  Search Details ********************************************/
            if (request.getParameter("MatSearch") != null)
            {
                System.out.println(" Matrimony search button clicked ");
                gender = request.getParameter("gender");
                age = request.getParameter("age");
                qual = request.getParameter("qual");
                System.out.print("gender is " + gender);
                System.out.print("age is " + age);
                System.out.print("qual is " + qual);
                ArrayList al = vmd.Mat_Search(gender,age,qual);
                if (al.size() != 0)
                request.getRequestDispatcher("Matrimonial/MatSearchMembers1.jsp").forward(request, response);
            }
        } catch (Exception e) {

            e.printStackTrace();

            System.out.print("Exception is :" + e);
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(ViewMatMember.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(ViewMatMember.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(ViewMatMember.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(ViewMatMember.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
